package com.maomao.hello;

public class FinalizeEsacpeGC {
	public static FinalizeEsacpeGC SAVE_HOOK = null;
	
	public void isAlive()
	{
		System.out.println("yes,I am alive");
	}
	
	@Override
	public void finalize() throws Throwable
	{
		super.finalize();
		System.out.println("finalize method excuted!");
		FinalizeEsacpeGC.SAVE_HOOK = this;	
	}
	
	public static void main(String[] args) throws Throwable {
		SAVE_HOOK = new FinalizeEsacpeGC();
		
		SAVE_HOOK =  null;
		System.gc();
		
		Thread.sleep(500);
		
		if(SAVE_HOOK != null)
		{
			SAVE_HOOK.isAlive();
		}
		else
		{
			System.out.println("NO,I am dead");
		}
		
		SAVE_HOOK = null;
		
		System.gc();
		
		Thread.sleep(500);
		
		if(SAVE_HOOK != null)
		{
			SAVE_HOOK.isAlive();
		}
		else
		{
			System.out.println("NO,I am dead");
		}
	}
}
